home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
bor_ti.exe
/
TI1155.ASC
< prev
next >
Wrap
Text File
|
1992-11-04
|
4KB
|
199 lines
PRODUCT : Borland C++ NUMBER : 1155
VERSION : 3.1
OS : DOS
DATE : November 4, 1992 PAGE : 1/2
TITLE : Detecting unusual keystrokes and key combinations.
Detecting unusual keystrokes and key combinations.
-------------------------------------------------
Some keystrokes, such as CTRL-1, cannot be caught with
bioskey() or an INT 15,4H interrupt handler because the BIOS does
not pass the scan code along to INT 15. If you need to catch
these keystrokes, you will need to intercept the keystroke
directly at the INT 9 level. This example of code demonstrates
exactly how to catch keystrokes such as CTRL-1. When the program
is run, keystrokes will echo the screen as normal, but whenever a
CTRL-1 is pressed, the machine will beep.
#include <dos.h>
#include <bios.h>
#include <stdio.h>
/* 0x02 is the value for 1 */
#define KEY_TO_CATCH 0x02
/* Old INT 9 handler routine */
void interrupt ( *Old09Handler )(...);
void interrupt New09Handler(...)
{
_AL = inportb( 0x60 ); // Read the Scan Code
if ( _AL == KEY_TO_CATCH ) // Is it that key?
{
_AH = 0x02; // Check the Shift
geninterrupt( 0x16 ); // Status using BIOS
if ( _AX & 0x04 ) // Is Control Held Down?
{
_AL = inportb( 0x61 ); // Reset the Keyboard
_AH = _AL;
_AL |= 0x80;
outportb( 0x61, _AL );
_AL = _AH;
outportb( 0x61, _AL );
outportb( 0x20, 0x20 ); // EOI to 8259
PRODUCT : Borland C++ NUMBER : 1155
VERSION : 3.1
OS : DOS
DATE : November 4, 1992 PAGE : 2/2
TITLE : Detecting unusual keystrokes and key combinations.
_AX = 0x0E07; // Beep to indicate that
geninterrupt( 0x10 ); // we caught the desired
// key
return; // Do not chain!
}
}
Old09Handler(); // Chain to Old Handler
}
int main( void )
{
Old09Handler = getvect( 0x09 ); // Save the original
setvect( 0x09, New09Handler ); // Install new
puts( "Please hit the ESC key to terminate..." );
LABEL:
asm {
mov ah, 8h
int 21h
or al, al
jz LABEL
mov dl, al
mov ah, 2
int 21h
cmp dl, 27
jne LABEL
}
setvect( 0x09, Old09Handler ); // Restore Original
return( 0 );
}
/*
Keywords: bioskey, CTRL-3, CTRL-4, CTRL-5, CTRL-7, CTRL-8,
CTRL-9, CTRL-0, keyboard, keypress
*/
DISCLAIMER: You have the right to use this technical information
subject to the terms of the No-Nonsense License Statement that
PRODUCT : Borland C++ NUMBER : 1155
VERSION : 3.1
OS : DOS
DATE : November 4, 1992 PAGE : 3/3
TITLE : Detecting unusual keystrokes and key combinations.
you received with the Borland product to which this information
pertains.